#ifndef FOOLISHGO_TRANSPOSITIONTABLE_H
#define FOOLISHGO_TRANSPOSITIONTABLE_H

#include <cstdint>

#include <vector>
#include <algorithm>

#include "macro_and_enum.h"

typedef struct {
	float averageInterest;
	int reachCount;
	bool isCompleted;
}SPositionInformation;

typedef struct {
	int32_t key;
	bool isFilled;
	SPositionInformation positionInformation;
} STableItem;

typedef std::vector<STableItem> TItemVector;

class CTestForCTranspositionTable;

class CTranspositionTable
{
public:

	CTranspositionTable(void);
	void Init(void);
	void Clean(void);
	~CTranspositionTable(void);

	bool Search(int32_t key, SPositionInformation *pResult) const;
	void Insert(int32_t key, const SPositionInformation &src);
	void Update(int32_t key, const SPositionInformation &src);

protected:
	inline int32_t GetScriptWithKey(int32_t key) const;
	int32_t GetNextScript(int32_t script) const;

private:
	DISALLOW_COPY_AND_ASSIGN(CTranspositionTable);

	friend class CTestForCTranspositionTable;

	int32_t m_Size;
	int32_t m_FilledCount;
	TItemVector m_ItemVector;
};


#endif